package com.zhangwei.liwushuo.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.zhangwei.liwushuo.bean.CategoryEntity;
import com.zhangwei.liwushuo.config.AppConfig;
import com.zhangwei.liwushuo.utils.FileUtils;

import java.sql.SQLException;

/**
 * @说 明：
 * @项目名称：LiWuShuo
 * @包 名： com.zhangwei.liwushuo.db
 * @类 名： AppDBHelper
 * @创 建人： zhangwei
 * @创建时间：2015-08-14 21:16
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

    public DatabaseHelper(Context context) {

        super(context, AppConfig.DATABASE_NAME, null, AppConfig.DATABASE_VERSION);
        String path = new FileUtils().getAppCache();
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(path, null);
        onCreate(db);
        db.close();
    }

    @Override
    public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
        try {
            TableUtils.clearTable(connectionSource, CategoryEntity.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {

    }


}
